# encoding : utf-8
# author   : 伦裕如

import pymysql

# 创建数据库连接
db = pymysql.connect(
    host='localhost',
    port=3306,
    database='jiangsu',
    user='root',
    password='root',
    charset='utf8'
)

# 创建游标
cursor = db.cursor()

# sql查询语句
columns = "s.s_id, s.s_name, s.s_birth, s.s_sex, sc.s_id, sc.c_id, sc.s_score"
sql = f"select {columns} from student s join score sc on sc.s_id = s.s_id"

# 执行sql语句
cursor.execute(sql)

# 获取所有查询结果
data = cursor.fetchall()

# 打印输出
print(columns)
for d in data:
    print(f'{d}')

# 关闭游标、数据库连接
cursor.close()
db.close()
